<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>
    Strange errors when running console : Forums : PythonAnywhere
</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Forums : PythonAnywhere">
        <meta name="author" content="PythonAnywhere LLP">
        <meta name="google-site-verification" content="O4UxDrfcHjC44jybs2vajc1GgRkTKCTRgVzeV6I9V14" />

        <!-- Le styles -->
        <link href="/static/bootstrap/css/bootstrap.css" rel="stylesheet">
        <link href="/static/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
        <link href="/static/anywhere/styles/bootstrap_base.css" rel="stylesheet">
        
    
    <link rel="stylesheet" href="/static/anywhere/styles/forums.css" type="text/css" media="screen" charset="utf-8" />

    <link rel="stylesheet" href="/static/pygments/style.css" type="text/css" media="screen" charset="utf-8" />

        <link rel="stylesheet" href="/static/jquery/jquery-ui-1.8.11.custom.css" type="text/css" media="screen" charset="utf-8" />
        
    
    <link rel="alternate" type="application/rss+xml" title="RSS" href="/forums/topic/840/rss" />

        <style type="text/css">
            body {
                height: auto;
            }
        </style>
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
        <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <!-- Le fav and touch icons -->
        <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
        <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
        <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
    </head>

     <body>
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div id="id_internal_nav_bar_container" class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    </a>
                    <a class="brand" href="/"><img id="id_logo" src="/static/anywhere/images/logo-234x35.png" height="35" title="PythonAnywhere logo" alt="PythonAnywhere logo" /></a>
                    <div class="nav-collapse">
                        <ul id="id_header_links" class="nav">
                            <li><a id="id_feedback_link" class='feedback_link' href="">Send feedback</a></li>
                            <li><a id="id_forums_link" href="/forums/">Forums</a></li>
                            <li><a href="/wiki/" id="id_help_link">Help</a></li>
                            <li><a href="http://blog.pythonanywhere.com/" id="id_blog_link">Blog</a></li>
                            
                            
                                <li><a style="font-weight: bold;" href="/pricing/" id="id_pricing_link">Pricing & signup</a></li>
                                <li><a href="/login/?next=/forums/topic/840/" id="id_login_link">Log in</a></li>
                            
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="top-container" id="id_dummy"></div>

        

        
    
    <div class="container">
        <div class="row">
            <div class="span8 offset3">
                <h1>PythonAnywhere Forums</h1>
            </div>
        </div>



    <div class="row">
        <div class="span8 offset3">
            <p>
                <a href="/forums/start_topic/" id="id_start_new_topic">Start a new topic</a> |
                <a href="/forums/">Back to all topics</a> |
                <a href="/forums/topic/840/rss">This topic's RSS</a>
            </p>
        </div>
    </div>
    <div class="row">
        <div class="span8 offset3 topic">
            <h2>Strange errors when running console</h2>
        </div>
    </div>

    
        <div class="row">
            <div id="id_post_5950" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5950_content_text" class="span8">
                        <p>Since late last night, I have been getting strange errors when starting a console (listed below). In addition, when I try to run any command in my bash shell, I get similar messages. Any idea what is going on? </p>
<p>bash: fork: retry: Resource temporarily unavailable                                                                                                 <br />
bash: fork: Interrupted system call                                                                                                                 <br />
bash: fork: retry: No child processes                                                                                                               <br />
bash: fork: retry: No child processes                                                                                                               <br />
bash: fork: retry: No child processes                                                                                                               <br />
bash: fork: retry: No child processes                                                                                                               <br />
bash: fork: Resource temporarily unavailable </p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5950_creator_details">
                            
                                
                                    <img src="/static/anywhere/images/star.gif" alt="Beloved premium user" title="Beloved premium user"/>
                                
                            
                            Beison
                            |
                            2
                            posts
                            |
                            
                        </span>
                        <span id="id_post_5950_created_date">
                            Aug. 17, 2013, 3:30 p.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/840/#id_post_5950">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    
        <div class="row">
            <div id="id_post_5959" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5959_content_text" class="span8">
                        <p>Hi Beison, the problem should be fixed for you now. </p>
<p>What caused it? Well we limit the number of processes a user can start to stop people fork bombing the servers. You had hundreds of Xvfb processes open. When you are writing scripts that open a process or resource. You should always make sure you close it.</p>
<p>If you use a </p>
<div class="codehilite"><pre><span class="k">try</span><span class="p">:</span>
    <span class="c"># normal code</span>
<span class="k">except</span><span class="p">:</span>
    <span class="k">raise</span>

<span class="k">finally</span><span class="p">:</span>
    <span class="c"># close my xvfb processes if they exist no matter what</span>
</pre></div>


<p>Around your entire code you can guarantee that it will happen, mostly :) </p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5959_creator_details">
                            
                                <img src="/static/anywhere/images/staff.png" alt="Staff" title="Staff"/>
                            
                            hansel
                            |
                            435
                            posts
                            |
                            
                                PythonAnywhere staff
                                |
                            
                        </span>
                        <span id="id_post_5959_created_date">
                            Aug. 18, 2013, 8:52 a.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/840/#id_post_5959">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    
        <div class="row">
            <div id="id_post_5967" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5967_content_text" class="span8">
                        <p>Thanks! I will be more careful with this going forward.</p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5967_creator_details">
                            
                                
                                    <img src="/static/anywhere/images/star.gif" alt="Beloved premium user" title="Beloved premium user"/>
                                
                            
                            Beison
                            |
                            2
                            posts
                            |
                            
                        </span>
                        <span id="id_post_5967_created_date">
                            Aug. 19, 2013, 4:52 a.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/840/#id_post_5967">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    
        <div class="row">
            <div id="id_post_5999" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5999_content_text" class="span8">
                        <p>One technique I've used in the past to guard against "hard" failures (i.e. segfaults and other crashes in the Python interpreter itself) is to create a "child-pids" directory where the name of the directory includes the PID of the parent. Every time I fork a child process, I create an empty file in the directory whose name is the PID of the child. When I reap a child process, I unlink the file. A single text file or database table would do just as well as the directory approach, but creating and removing files is just more convenient and I was feeling lazy at the time.</p>
<p>Anyway, the point is that you can then have a scheduled task which periodically scans these directories. For each parent PID directory it sends SIGKILL to each PID file within that directory and then removes the file.</p>
<p>You have to remember to remove the directory and files at the point your application terminates cleanly, and ideally you'd check process names before killing them, although I'm not aware of a way to do this on PA currently. Also it's worth noting that you only tend to need to do this in the case of processes which are designed to run as a daemon. If you're using <code>subprocess</code> with something which reads from its standard input, for example, closing the parent will close the input filehandle and hence the child process will get a <code>read()</code> of size 0 and generally terminate. It all depends on the behaviour of the applications concerned.</p>
<p>The risk is that you might end up killing the wrong process if, say, one of your children has silently exited and another process has reused the same PID. On a shared system like PA, however, the chances of that PID being reused by one of <em>your</em> processes (you won't have permission to terminate anybody else's) are slim.</p>
<p>Anyway, you might consider an approach like this if you find you run into this problem regularly.</p>
<p>EDIT: It occurs to me that while you can't check the process name or command-line on PA, you can use Python's <a href="http://docs.python.org/2/library/os.html#os.getpgid"><code>os.getpgid()</code></a> to get the process's group ID. If you also record the group ID of the parent in the directory name, you can use this as an additional check that you've got the correct process. This assumes that child processes don't change their process group (i.e. don't call <code>os.setpgid()</code>).</p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5999_creator_details">
                            
                                
                                    <img src="/static/anywhere/images/star.gif" alt="Beloved premium user" title="Beloved premium user"/>
                                
                            
                            Cartroo
                            |
                            638
                            posts
                            |
                            
                        </span>
                        <span id="id_post_5999_created_date">
                            Aug. 21, 2013, 7:28 a.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/840/#id_post_5999">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    
        <div class="row">
            <div id="id_post_6002" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_6002_content_text" class="span8">
                        <p>That's a nice idea, but it's worth noting (in case it's not obvious) that the scheduled task-based reaping of rogue child processes won't work for children of things you've started from the console -- they run on different machines.  But right now all of your scheduled tasks will run on the same machine, so it will definitely work for children of scheduled tasks.</p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_6002_creator_details">
                            
                                <img src="/static/anywhere/images/staff.png" alt="Staff" title="Staff"/>
                            
                            giles
                            |
                            866
                            posts
                            |
                            
                                PythonAnywhere staff
                                |
                            
                        </span>
                        <span id="id_post_6002_created_date">
                            Aug. 21, 2013, 10:09 a.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/840/#id_post_6002">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    

    




        <div id="id_footer" class="container">

            <footer id="id_copyright_div">
                <p>
                    Copyright &copy; 2013 PythonAnywhere LLP
                    &mdash;
                    <a href="/terms/">Terms</a>
                    &mdash;
                    <a href="/privacy/">Privacy</a><br/>
                    "Python" is a registered trademark of the Python Software Foundation.
                </p>
            </footer>

        </div>

        
        

        <div id="id_feedback_dialog" title="Help us improve" style="display:none">
    <div id="id_feedback_dialog_blurb_big" class="dialog_blurb_big">
        It's always a pleasure to hear from you!
    </div>
    <div id="id_feedback_dialog_blurb_small">
        Ask us a question, or tell us what you love or hate about PythonAnywhere.<br/>
        We'll get back to you over email ASAP.
    </div>
    <textarea id="id_feedback_dialog_text" rows="6"></textarea>
    <input id="id_feedback_dialog_email_address" type="text" class="default_prompt"/>
    <div id="id_feedback_dialog_error" class="pa_hidden">
        Sorry, there was an error connecting to the server. <br/>Please try again in a few moments...
    </div>
    <div class="dialog_buttons">
        <img id="id_feedback_dialog_spinner" src="/static/anywhere/images/spinner-small.gif" />
        <button class="btn btn-primary" id="id_feedback_dialog_ok_button">OK</button>
        <button class="btn" id="id_feedback_dialog_cancel_button">Cancel</button>
    </div>
</div>


        <!-- Le javascript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <script type="text/javascript" src="/static/jquery/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="/static/jquery/jquery-ui-1.8.11.custom.min.js"></script>
        <script src="/static/bootstrap/js/bootstrap-transition.js"></script>
        <script src="/static/bootstrap/js/bootstrap-alert.js"></script>
        <script src="/static/bootstrap/js/bootstrap-modal.js"></script>
        <script src="/static/bootstrap/js/bootstrap-dropdown.js"></script>
        <script src="/static/bootstrap/js/bootstrap-scrollspy.js"></script>
        <script src="/static/bootstrap/js/bootstrap-tab.js"></script>
        <script src="/static/bootstrap/js/bootstrap-tooltip.js"></script>
        <script src="/static/bootstrap/js/bootstrap-popover.js"></script>
        <script src="/static/bootstrap/js/bootstrap-button.js"></script>
        <script src="/static/bootstrap/js/bootstrap-collapse.js"></script>
        <script src="/static/bootstrap/js/bootstrap-carousel.js"></script>
        <script src="/static/bootstrap/js/bootstrap-typeahead.js"></script>

        <script type="text/javascript">
            var urls = {};
            var Anywhere = {};
            Anywhere.urls = {};
        </script>
        <script type="text/javascript" src="/static/anywhere/scripts/ajax_utils.js"></script>

        <script type="text/javascript" src="/static/anywhere/scripts/feedback_dialog.js"></script>
        
        <script type="text/javascript">
            $(function() {
                $.extend(
                    urls,
                    {
                        feedback: '/feedback/submit/'
                    }
                );
                
                    Anywhere.FeedbackDialog.Initialise(urls, true);
                
            });
        </script>

        <script type="text/javascript">

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-18014859-6']);
            _gaq.push(['_trackPageview']);

            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();

        </script>

        



    </body>
</html>
